/**
 * Created with IntelliJ IDEA.
 * User: chenkaiyu
 * Date: 15-5-26
 * Time: 下午7:05
 * To change this template use File | Settings | File Templates.
 */

var sodaParameter = function () {
    var saveValidate=function(){
        var E3 = $("#E3").val();
        if (E3 == "") {
            toast.error("过热蒸汽流量Dgr 不能为空！")
            return false;
        }
        var E4 = $("#E4").val();
        if (E4 == "") {
            toast.error("过热蒸汽压力Pgr 不能为空！")
            return false;
        }
        var E5 = $("#E5").val();
        if (E5 == "") {
            toast.error("过热蒸汽温度Tgr 不能为空！")
            return false;
        }
        var E7 = $("#E7").val();
        if (E7 == "") {
            toast.error("给水压力Pgs 不能为空！")
            return false;
        }

        var E8 = $("#E8").val();
        if (E8 == "") {
            toast.error("给水温度Tgs 不能为空！")
            return false;
        }

        return true;
    }

    var getValueZero = function (obj) {
        var value = obj.val();
        if (value.trim() == "") {
            return 0;
        } else {
            return obj.val();
        }
    }
    var getSodaParameter = function () {
        return{
            dgr:$("#E3").val(),
            pgr:$("#E4").val(),
            tgr:$("#E5").val(),
            pgs:$("#E7").val(),
            tgs:$("#E8").val(),

            dzr:getValueZero($("#E13")),
            pzr:getValueZero($("#E14")),
            tzr:getValueZero($("#E15")),
            pzr3:getValueZero($("#E17")),
            tzr3:getValueZero($("#E18")),

            pqb:getValueZero($("#E10")),
            tqb:getValueZero($("#E11")),
            ddesS:getValueZero($("#E20")),
            pdesS:getValueZero($("#E21")),
            tdesS:getValueZero($("#E22")),

            ddesR:getValueZero($("#E24")),
            pdesR:getValueZero($("#E25")),
            tdesR:getValueZero($("#E26")),
            dpw:getValueZero($("#E29")),
            powerCaseId: $("#caseId").val()
        }
    }

    return {
        init: function () {

        },
        sodaParameterNext: function () {
            var addFlag = $("#addFlag").val();
            if (addFlag == "add") {
                toast.error("请先填写本页数据，保存成功后再进行下一页操作！");
                return;
            }
            formSub(basePath + "boiler/airgas?menuId=19")
        },
        sodaParameterSave: function () {
            if (!saveValidate())return;
            var addFlag = $("#addFlag").val();
            if (addFlag == "add" || (addFlag != "add" && confirm("确定重新计算并保存吗？"))) {
                Metronic.blockUI({
                    boxed: true,
                    message: "数据加载中..."
                });
                $.ajax({
                    url: basePath + "boiler/gasogene/sodaParameterSave",
                    type: "post",
                    dataType: "json",
                    data: getSodaParameter(),
                    success: function (data) {
                        Metronic.unblockUI();
                        if (data.ok) {
                            formSub(basePath + "boiler/gasogene?menuId=18&message=success")
                        } else if (data.error) {
                            toast.error(data.returnMsg);
                            return false;
                        }
                    }
                })
            }
        }
    }
}
();
